package hr.dao;

import hr.entities.Locations;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * Data access object (DAO) for domain model class Locations.
 * 
 * @see hr.entities.Locations
 * @author MyEclipse Persistence Tools
 */

public class LocationsDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(LocationsDAO.class);
	// property constants
	public static final String STREET_ADDRESS = "streetAddress";
	public static final String POSTAL_CODE = "postalCode";
	public static final String CITY = "city";
	public static final String STATE_PROVINCE = "stateProvince";

	public void save(Locations transientInstance) {
		log.debug("saving Locations instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Locations persistentInstance) {
		log.debug("deleting Locations instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Locations findById(java.lang.Long id) {
		log.debug("getting Locations instance with id: " + id);
		try {
			Locations instance = (Locations) getSession().get("hr.Locations",
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Locations instance) {
		log.debug("finding Locations instance by example");
		try {
			List results = getSession().createCriteria("hr.Locations").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Locations instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Locations as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByStreetAddress(Object streetAddress) {
		return findByProperty(STREET_ADDRESS, streetAddress);
	}

	public List findByPostalCode(Object postalCode) {
		return findByProperty(POSTAL_CODE, postalCode);
	}

	public List findByCity(Object city) {
		return findByProperty(CITY, city);
	}

	public List findByStateProvince(Object stateProvince) {
		return findByProperty(STATE_PROVINCE, stateProvince);
	}

	public List findAll() {
		log.debug("finding all Locations instances");
		try {
			String queryString = "from Locations";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Locations merge(Locations detachedInstance) {
		log.debug("merging Locations instance");
		try {
			Locations result = (Locations) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Locations instance) {
		log.debug("attaching dirty Locations instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Locations instance) {
		log.debug("attaching clean Locations instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}